clear all

*********Set working directory and load data
local user: env USERNAME
if "`user'" == "ENTERYOURNAME"  cd "SETYOURDIRECTORY"
else if "`user'" == "sagomm"  cd "C:\Users\sagomm\Dropbox\SEP-Trust\Analysis\" 

use "Data\w9_conjoint.dta"

******Install necesarry user-written commands
do "Scripts\functions\function_conjoint.do"
do "Scripts\functions\function_addplot.do"

************ Policy Packages: One Actor **********
//estimate conjoint coefficients
reg choice ///
	i.stringency_f year if actor < 5, ///
	cluster(PubId)
	
eststo reg_int_all

*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est res reg_int_all
margins, at(stringency_f=(1(1)3)) post
est sto mar_int_all

//Plot package figure
coefplot mar_int_all, keep(1._at 2._at 3._at) ///
title("Single actor", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	mc(edkblue) msize(small) ciopts(lc(edkblue)) ///
	xtitle("Pr(Selecting Proposal)") ///
	xlab(0.2(0.2)0.8, format(%2.1f)) ///
	xline(0.50, lp(shortdash) lc(gs5)) ///
	coefl( ///
		1._at = "Low Stringency" ///
		2._at = "Medium Stringency" ///
		3._at = "High Stringency" ///
		) ///
	 r2title("{bf:  }", orientation(rvertical)) ///
	 xlabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(fig_1, replace) 
	
************ Policy Packages: All Actors **********
//estimate conjoint coefficients
reg choice ///
	i.stringency_f year if actor > 4, ///
	cluster(PubId)
	
eststo reg_int_all

*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est res reg_int_all
margins, at(stringency_f=(1(1)3)) post
est sto mar_int_all

//Plot package figure
coefplot mar_int_all, keep(1._at 2._at 3._at) ///
title("Multiple actors", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	mc(edkblue) msize(small) ciopts(lc(edkblue)) ///
	xtitle("Pr(Selecting Proposal)") ///
	xlab(0.2(0.2)0.8, format(%2.1f)) ///
	xline(0.50, lp(shortdash) lc(gs5)) ///
	coefl( ///
		1._at = "Low Stringency" ///
		2._at = "Medium Stringency" ///
		3._at = "High Stringency" ///
		) ///
	 r2title("{bf:  }", orientation(rvertical)) ///
	  xlabel(,labsize(small)) ///
		graphregion(color(white)) ///
	name(fig_2, replace) 
	
//Combine graphs
gr combine ///
	fig_1 ///
	fig_2, ///
	graphregion(color(white)) ///
	name(fig1fig2_comb, replace)
		
graph display, ysize(30) xsize(60)

graph export "Plots\Figure2b_packages_choice.png", as(png) name("fig1fig2_comb") width(1800) replace



**********************************************************************
*                           Binary Rating                            *
**********************************************************************

************ Policy Packages: One Actor **********
//estimate conjoint coefficients
reg binary ///
	i.stringency_f year if actor < 5, ///
	cluster(PubId)
	
eststo reg_int_all

*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est res reg_int_all
margins, at(stringency_f=(1(1)3)) post
est sto mar_int_all

//Plot package figure
coefplot mar_int_all, keep(1._at 2._at 3._at) ///
title("Single actor", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	mc(edkblue) msize(small) ciopts(lc(edkblue)) ///
	xtitle("Pr(Selecting Proposal)") ///
	xlab(0.2(0.2)0.8, format(%2.1f)) ///
	xline(0.50, lp(shortdash) lc(gs5)) ///
	coefl( ///
		1._at = "Low Stringency" ///
		2._at = "Medium Stringency" ///
		3._at = "High Stringency" ///
		) ///
	 r2title("{bf:  }", orientation(rvertical)) ///
	  xlabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(fig_1, replace) 
	
************ Policy Packages: All Actors **********
//estimate conjoint coefficients
reg binary ///
	i.stringency_f year if actor > 4, ///
	cluster(PubId)
	
eststo reg_int_all

*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est res reg_int_all
margins, at(stringency_f=(1(1)3)) post
est sto mar_int_all

//Plot package figure
coefplot mar_int_all, keep(1._at 2._at 3._at) ///
title("Multiple actors", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	mc(edkblue) msize(small) ciopts(lc(edkblue)) ///
	xtitle("Pr(Selecting Proposal)") ///
	xlab(0.2(0.2)0.8, format(%2.1f)) ///
	xline(0.50, lp(shortdash) lc(gs5)) ///
	coefl( ///
		1._at = "Low Stringency" ///
		2._at = "Medium Stringency" ///
		3._at = "High Stringency" ///
		) ///
	 r2title("{bf:  }", orientation(rvertical)) ///
	  xlabel(,labsize(small)) ///
	graphregion(color(white)) ///
	name(fig_2, replace) 
	
//Combine graphs
gr combine ///
	fig_1 ///
	fig_2, ///
	graphregion(color(white)) ///
	name(fig1fig2_comb, replace)
		
graph display, ysize(30) xsize(60)

graph export "Plots\Figure2c_packages_binary.png", as(png) name("fig1fig2_comb") width(3800) replace
